#pragma once

#include <atomic>
#include <thread>

#include <android/native_window.h>

class HiSurfaceView {
 public:
  explicit HiSurfaceView(ANativeWindow *window);
  ~HiSurfaceView();

  void OnWindowChanged(ANativeWindow *window,
      int format, int width, int height);

 private:
  void StartDrawing();
  void StopDrawing();
  void Run();
  void OnDraw(ANativeWindow_Buffer *buffer, ARect *rect);

  void ReleaseWindow();

  ANativeWindow *window_;

  std::thread draw_thread_;
  std::atomic_bool is_drawing_;
};
